package com.googlecode.project4uz.demo;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.LinkedList;

import org.openrdf.rio.RDFFormat;
import org.openrdf.rio.RDFHandlerException;
import org.openrdf.rio.RDFParseException;

import com.googlecode.project4uz.decoder.RioReader;
import com.googlecode.project4uz.encoder.RDFEncoder;
import com.googlecode.project4uz.encoder.Serializer;

public class RDFDecoderBeans {

	public static void main(String[] args) {
		RDFEncoder e = null;
		try {
			e = new RDFEncoder(RDFFormat.RDFXML, Serializer.BEANS,
					new BufferedOutputStream(
							new FileOutputStream("demoXXX.rdf")));
		} catch (FileNotFoundException e1) {

			e1.printStackTrace();
		}
		BeanTestClass c = new BeanTestClass();
		LinkedList<Double> lista = new LinkedList<Double>();
		lista.add(3.4);
		c.setLista(lista);
		c.setText("CZESC");
		c.setCalkowita(0);
		BeanTestWewnetrznaKlasa a=new BeanTestWewnetrznaKlasa();
		a.setCalkowita(0);
		c.setKlasaWew(a);
		c.setZmiennoprzecinkowa(4.4);

		e.writeObject(c);
		e.close();
		RioReader reader = null;
		try {
			reader = new RioReader(RDFFormat.RDFXML, new BufferedInputStream(
					new FileInputStream("demoXXX.rdf")));
		} catch (NumberFormatException e1) {

			e1.printStackTrace();
		} catch (RDFParseException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (RDFHandlerException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (SecurityException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (IllegalArgumentException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (FileNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (NoSuchMethodException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (ClassNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (InstantiationException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (IllegalAccessException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (InvocationTargetException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (NoSuchFieldException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (Exception e2) {

		}
		BeanTestClass o = null;

		o = (BeanTestClass) reader.readObject();

		System.out.println("\n\n" + o.getText());
		System.out.println(o.getZmiennoprzecinkowa());
		System.out.println(o.getKlasaWew().getCalkowita());
		for (int i = 0; i < o.getLista().size(); i++)
			System.out.println(o.getLista().get(i));

	}

}
